﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Qreed.Windows.ComponentModel
{
    internal class PropertyBagExpandableItemDescriptor : PropertyBagItemDescriptor
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyBagExpandableItemDescriptor"/> class.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="attributes">The attributes.</param>
        public PropertyBagExpandableItemDescriptor(PropertyBagItem item, Attribute[] attributes)
            : base(item, attributes)
        {
        }

        /// <summary>
        /// Gets the <see cref="PropertyBagItem"/>.
        /// </summary>
        /// <value>The item.</value>
        public new PropertyBagExpandableItem Item
        {
            get { return (PropertyBagExpandableItem)base.Item; }
        }

        /// <summary>
        /// When overridden in a derived class, determines a value indicating whether the value of this property needs to be persisted.
        /// </summary>
        /// <param name="component">The component with the property to be examined for persistence.</param>
        /// <returns>
        /// true if the property should be persisted; otherwise, false.
        /// </returns>
        public override bool ShouldSerializeValue(object component)
        {
            PropertyDescriptorCollection props = Item.Items.GetProperties(null);

            foreach (PropertyDescriptor prop in props)
            {
                if (prop.ShouldSerializeValue(component))
                    return true;
            }

            return false;
        }
    }
}
